﻿@using MVC_da.Models.Database
@{ 
    var categorys = ViewData["category"] as List<Category>;
    var goods = ViewData["xinwens"] as List<Xinwen>;
    var cid = (int)ViewData["cid"];
}
<link rel="stylesheet" href="~/css/index.css">
<head>

</head>
<body>
    <div class="content">
        <div id="main">
            <ul id="main_ul">
                @{
                    int row;
                    //商品的总数
                    //行数：如果总数除以4能除尽  =商品的总数/4
                    //     除不尽 商品的总数/4+1
                    //除得尽的情况
                    if (goods.Count % 2 == 0)
                    {
                        row = goods.Count / 2;
                    }
                    else
                    {
                        //整型除以整型 結果是一個整型
                        //41/4 10.25 = 10
                        row = goods.Count / 2 + 1;
                    }

                    for (var i = 1; i <= row; i++)
                    {
                        //1 1-4
                        //2 5-8
                        //3 9-12
                        <div>
                            @{
                                //这里不需要在连接数据库 执行SQL了
                                var list = goods.Skip((i - 1) * 2).Take(2).ToList();
                                foreach (var item in list)
                                {
                                <li>
                                    <a href="detail.html?nno=@item.Nno">
                                        <img src="@item.Npictureurl" alt="">
                                        <p>@item.Ntitle</p>
                                        <p>
                                            @item.Ncontent
                                        </p>
                                        <p>时间：@item.Ntime</p>
                                        <p>来源：@item.Nsource</p>
                                    </a>
                                </li>
                            }
                            }
                    </div>
                }
                }
                </ul>
            </div>
        <div class="paging">
            <ul class="pagination">
                <li><a href="javascript:void(0)">«</a></li>
                <li><a class="active" href="javascript:void(0)">1</a></li>
                <li><a href="javascript:void(0)">2</a></li>
                <li><a href="javascript:void(0)">3</a></li>
                <li><a href="javascript:void(0)">4</a></li>
                <li><a href="javascript:void(0)">5</a></li>
                <li><a href="javascript:void(0)">6</a></li>
                <li><a href="javascript:void(0)">7</a></li>
                <li><a href="javascript:void(0)">»</a></li>
            </ul>
        </div>
        
    </div>
</body>